<template>
  <div>
    <el-row  type="flex" class="row-bg">
      <el-col>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">

        <el-form-item label="订单类型">
          <el-select v-model="formInline.selectedVal" clearable placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="搜索">
          <el-input v-model="formInline.searchVal" placeholder="请输入手机号/用户名/订单号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
      </el-col>
    </el-row>

    <el-table border  :data="tableData" stripe style="width: 100%">
      <el-table-column align="center" type="index" label="序号"></el-table-column>
      <el-table-column  align="center" prop="id" label="编号"> </el-table-column>
      <el-table-column  align="center" prop="name" label="用户名"> </el-table-column>
      <el-table-column  align="center" prop="phoneNum" label="手机号"> </el-table-column>
      <el-table-column  align="center" prop="type" label="类型"></el-table-column>
      <el-table-column  align="center" prop="price" label="支付金额"></el-table-column>
      <el-table-column  align="center" prop="payTime" label="支付时间"></el-table-column>
      <el-table-column align="center" label="操作" width="150">
        <template slot-scope="scoped">
          <el-button @click="delData(scoped.row)" size="mini" type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row>
      <el-col>
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageindex"
          :page-sizes="[5, 10, 15]"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import api from '@/api'
export default {
  data () {
    return {
      options: [{
        value: '二手房出租',
        label: '二手房出租'
      }, {
        value: '有房出租',
        label: '有房出租'
      }, {
        value: '我想买个房',
        label: '我想买个房'
      }, {
        value: '我想租个房',
        label: '我想租个房'
      }],
      formInline: {
        searchVal: '',
        selectedVal: ''
      },

      tableData: [],
      total: 0,
      pageindex: 1,
      pagesize: 10
    }
  },
  created () {
    this.getList()
  },
  methods: {
    async getList () {
      const { pageindex, pagesize, searchVal: keyWord } = this
      const { data } = await api.getorderList({ pageindex, pagesize, keyWord })
      if (data.meta.status) {
        this.tableData = data.data.list
        this.total = data.data.total
      }
      console.log(data)
    },
    async editData () {},
    async delData (row) {
      try {
        const { id } = row
        await this.$confirm('确认删除吗？')
        const { data } = await api.delorderList({ id })
        if (data.meta.status) {
          this.$message.success(data.meta.msg)
          this.getList()
        } else {
          this.$message.error(data.meta.msg)
        }
      } catch (error) {
        this.$message.info('取消删除')
      }
    },
    async onSubmit () {},
    handleSizeChange (size) {
      this.pagesize = size
      this.getList()
    },
    handleCurrentChange (index) {
      this.pageindex = index
      this.getList()
    }
  }

}
</script>

<style lang="less" scoped>

</style>
